<!DOCTYPE html>
<html lang="zh-CN"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	layout:decorator="layout/default">
<head>
<meta charset="UTF-8">
<title>账号管理</title>
<script type="text/javascript">
	var remoteUrl = '[[@{/sys/user/checkLoginName}]]';
	$(document).ready(
			function() {
				$("#loginName").focus();
				var validateMessageBox = $('#validateMessageBox');
				var userEditForm = $('#userEditForm');
				userEditForm.validate({
					errorElement : 'label',
					errorClass : 'help-block',
					focusInvalid : true,
					ignore : "",
					rules : {
					},
					messages : {
					},
					errorContainer : validateMessageBox,
					errorPlacement : function(error, element) {

						this.errorContainer.addClass('note-danger').html(
								"<p>输入有误，请先更正。</p>").show();
						var formGroup = $(element).closest('.form-group');
						var errorElement = formGroup.children('span.'
								+ this.errorClass);
						if (!errorElement || errorElement.length == 0) {
							errorElement = $('<span/>').addClass(
									this.errorClass);
							errorElement.appendTo(formGroup);
						}
						error.appendTo(errorElement);

					},
					highlight : function(element) {
						$(element).closest('.form-group').removeClass(
								'has-success').addClass('has-error');
					},

					unhighlight : function(element) {
						$(element).closest('.form-group').removeClass(
								'has-error').addClass('has-success');
					},

					success : function(label, element) {
						label.closest('.form-group').removeClass('has-error');
					},

					submitHandler : function(form) {
						App.blockUI(window, true);
						form.submit();
					}
				});
			});
	function goBack() {
		location.href = "[[@{/sys/user}]]";
	}
	
	

	function officeData(extId) {
		var url = "[[@{/sys/office/treeDataChild}]]";
		$.ajax({
			type : "post",
			url : url,
			data : {
				"type" : 2,
				"extId" : extId
			},
			dataType : "json",
			async : true,
			success : function(data) {
				$("#office_name").val("");
				var setting = {
					view : {
						dblClickExpand : false
					},
					data : {
						simpleData : {
							enable : true
						}
					},
					callback : {
						onDblClick : onDblClick
					}
				};
				
				 function onDblClick(event, treeId, treeNode) {
		                $("#office_id").val(treeNode.id);
		                $("#office_name").val(treeNode.name);
		                $("#office_tree_div").modal('hide');
		                
		            }

				 var initMenuTree  = function (data) {
		                var $zTree = $.fn.zTree.init($("#office_menuTree"), setting, data);
		                // 默认展开一级节点
		                var nodes = $zTree.expandAll(true);
		            }(data);
	            

			},
			error : function(data) {
				if(data.status==200){
// 					document.write(data.responseText);
					location.href="[[@{/login}]]";
				}
			}
		});
	}
	
	function roleData(orgId){
		var url = "[[@{/sys/role/getRoleByOrg}]]";
		$.ajax({
			type : "post",
			url : url,
			data : {
				"orgId" : orgId
			},
			dataType : "",
			async : true,
			success : function(data) {
				if(data==''|| data == null){
		            $(".role_list").html("");
					return;
				}
				var htmlRole = ''; 
				$.each(data, function(index,item){
					htmlRole += "<input type=\"checkbox\" name=\"roleIdList\" value='"+item.id+"'/>"+item.name;
				});
	            $(".role_list").html(htmlRole);

			},
			error : function(data) {
				if(data.status==200){
// 					document.write(data.responseText);
					location.href="[[@{/login}]]";
				}
			}
		});
	}
</script>
</head>
<body shiro:has-permission="sys:user:view">
	<div layout:fragment="content" th:remove="tag">
		<div
			th:replace="fragments/toolAccount :: tipMessage (type='',content=${message})"
			th:remove="tag"></div>
		<div class="row">
			<div class="col-md-12">
				<!-- BEGIN PAGE TITLE & BREADCRUMB-->
				<ul class="page-breadcrumb breadcrumb">
					<li><i class="fa fa-home"></i> <a th:href="@{/}">首页</a> <i
						class="fa fa-angle-right"></i></li>
					<li><a href="#">权限管理</a> <i class="fa fa-angle-right"></i></li>
					<li><a th:href="@{/sys/user}">账号管理</a></li>
				</ul>
				<!-- END PAGE TITLE & BREADCRUMB-->

			</div>
		</div>


		<div class="row">
			<div class="col-md-1"></div>
			<div class="col-md-10">
				<!--BEGIN TABS-->
				<div class="tabbable tabbable-custom tabbable-full-width">
					<div class="tab-content" style="border: none;">
						<div class="tab-pane active" id="user_tab_1_2">
							<div class="portlet box blue">
								<div class="portlet-body form">
									<!-- BEGIN FORM-->
									<form id="userEditForm" class="form-horizontal"
										th:object="${user}" th:action="@{/sys/user/save}"
										method="post">
										<input type="hidden" th:field="*{id}" />
										<div class="form-body" style="background-color: #fff;">
											<div class="form-group">
												<label class="col-md-3 control-label">所属机构<span
													class="required">*</span></label>
												<div class="col-md-6">
	                                            	<th:block th:if="${not #strings.isEmpty(user.id)}">
	                                            		<input th:field="*{company.name}" class="form-control" th:readonly="true" type="text"/>
	                                            		<input th:field="*{company.id}" class="office-id" th:readonly="true" type="hidden"/>
	                                            	</th:block>
	                                            	<th:block th:if="${#strings.isEmpty(user.id)}">
		                                                <div th:replace="fragments/tool :: treeSelect (id='company',name='company.id', labelName='company.name', nameVal=${user.company.id}, labelVal=${user.company.name}, cssClass='required', placeholder='', dialogTitle='公司', remoteUrl='/sys/office/treeData?type=1', always=true)"></div>
													</th:block>
	                                            </div>
											</div>
											<div class="form-group">
												<label class="col-md-3 control-label">所在部门<span
													class="required">*</span></label>
												<div class="col-md-6 office-data">
													<th:block th:if="${not #strings.isEmpty(user.loginName)}">
	                                            		<div th:replace="fragments/toolAccount :: treeSelect (id='office',name='office.id', labelName='office.name', nameVal=${user.office.id},companyVal=${user.company.id}, labelVal=${user.office.name}, cssClass='required', placeholder='', dialogTitle='部门', remoteUrl='/sys/office/treeDataChild?type=2', always=true)"></div>
													</th:block>
                                            		<th:block th:if="${#strings.isEmpty(user.loginName)}">
		                                                <div th:replace="fragments/toolAccount :: treeSelect (id='office',name='office.id', labelName='office.name', nameVal='${user.office.id}',companyVal=${user.company.id}, labelVal='', cssClass='required', placeholder='', dialogTitle='部门', remoteUrl='/sys/office/treeDataChild?type=2', always=true)"></div>
													</th:block>
												</div>
											</div>  
											<div class="form-group">
												<label class="col-md-3 control-label">账号名称<span
													class="required">*</span></label>
												<div class="col-md-6">
													<input type="hidden" th:value="${user.loginName}"
														name="oldLoginName" /> <input type="text"
														class="form-control required" th:field="*{loginName}"
														th:maxlength="${#strings.isEmpty(user.id)}?20" 
														th:readonly="${not #strings.isEmpty(user.loginName) and not  #strings.isEmpty(user.id)}" />
												</div>
											</div>
											<div class="form-group">
												<label class="col-md-3 control-label">真实姓名<span
													class="required">*</span></label>
												<div class="col-md-6">
													<input type="text" class="form-control required" 
														th:field="*{realName}" maxlength="20" />
												</div>
											</div>
											<div class="form-group">
												<label class="col-md-3 control-label">邮箱<span
													class="required">*</span></label>
												<div class="col-md-6">
													<input type="text" class="form-control email required"
														th:field="*{email}" maxlength="64" />
												</div>
											</div>
											<div class="form-group">
												<label class="col-md-3 control-label">电话</label>
												<div class="col-md-6">
													<input type="text" class="form-control"
														th:field="*{mobile}" maxlength="11" />
												</div>
											</div>

											<div class="form-group">
												<label class="col-md-3 control-label">备注</label>
												<div class="col-md-6">
													<textarea th:field="*{remarks}" rows="3" maxlength="100"
														class="form-control"></textarea>
												</div>
											</div>
											<div class="form-group last">
												<label class="col-md-3 control-label">账号角色 </label>
												<div class="col-md-6 role_list" style="padding-top: 8px;" id="roleIdList">
													<input type="checkbox" name="roleIdList"
														th:each="role : ${allRoles}" th:checked="${role.checked}"
														th:value="${role.id}" th:text="${role.name}" />
												</div>
											</div>

										</div>
										<div class="form-actions fluid">
											<div class="col-md-offset-3 col-md-6" style="text-align: right;">
												<button type="submit" class="btn blue" shiro:has-any-permissions="sys:user:edit,sys:user:add">保 存</button>
												<button type="button" class="btn default" onclick="goBack()">返
													回</button>
											</div>
										</div>
									</form>
									<!-- END FORM-->
								</div>

							</div>

						</div>
					</div>
				</div>
			</div>
		</div>


	</div>


</body>
</html>
